package com.powernode.driver.service.impl;


import com.powernode.common.execption.PowerException;
import com.powernode.common.result.ResultCodeEnum;
import com.powernode.driver.client.DriverInfoFeignClient;
import com.powernode.driver.service.LocationService;
import com.powernode.map.client.LocationFeignClient;
import com.powernode.model.entity.driver.DriverSet;
import com.powernode.model.form.map.OrderServiceLocationForm;
import com.powernode.model.form.map.UpdateDriverLocationForm;
import com.powernode.model.form.map.UpdateOrderLocationForm;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class LocationServiceImpl implements LocationService {

    @Resource
    private LocationFeignClient locationFeignClient;

    @Resource
    private DriverInfoFeignClient driverInfoFeignClient;

    /**
     * 更新配送员位置
     */
    @Override
    public Boolean updateDriverLocation(UpdateDriverLocationForm updateDriverLocationForm) {
        //查看配送员的个性化配置，是否开启接单
        DriverSet driverSet = driverInfoFeignClient.getDriverSet(updateDriverLocationForm.getDriverId()).getData();

        if (driverSet.getServiceStatus() == 1) {//1表示开启接单
            //更新配送员位置
            return locationFeignClient.updateDriverLocation(updateDriverLocationForm).getData();
        }

        throw new PowerException(ResultCodeEnum.NO_START_SERVICE);
    }

    /**
     * 配送员更新自己的位置信息
     */
    @Override
    public Boolean updateOrderLocationToCache(UpdateOrderLocationForm updateOrderLocationForm) {
        return locationFeignClient.updateOrderLocationToCache(updateOrderLocationForm).getData();
    }


    /**
     * 配送员配送中更新自己的位置信息
     */
    @Override
    public Boolean updateOrderLocation(List<OrderServiceLocationForm> orderServiceLocations) {
        return locationFeignClient.saveOrderServiceLocation(orderServiceLocations).getData();
    }
}
